# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer:
pkgname=merlin
pkgver=4.5
_ocamlver=4.14
_pkgver="$pkgver-${_ocamlver//./}"
pkgrel=1
pkgdesc="Context sensitive completion for OCaml"
url="https://ocaml.github.io/merlin/"
arch="all !riscv64" # restricted by ocaml
license="MIT"
depends="ocaml-runtime ocaml-findlib"
makedepends="
	dune
	ocaml
	ocaml-findlib-dev
	ocaml-yojson-dev
	ocaml-menhir-dev
	ocaml-csexp-dev
	"
options="!check"  # XXX: tests are broken, see https://github.com/ocaml/merlin/issues/766
subpackages="$pkgname-emacs::noarch $pkgname-vim::noarch"
source="$pkgname-$pkgver.tar.bz2::https://github.com/ocaml/merlin/releases/download/v$_pkgver/merlin-$_pkgver.tbz"
builddir="$srcdir/$pkgname-$_pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build -p merlin,dot-merlin-reader @install --no-buffer --verbose
}

check() {
	dune runtest --no-buffer --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml \
		merlin dot-merlin-reader

	rm -Rvf "$pkgdir"/usr/doc
}

emacs() {
	pkgdesc="$pkgdesc in Emacs"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"

	amove usr/share/emacs
}

vim() {
	pkgdesc="$pkgdesc in vim"
	depends="$pkgname=$pkgver-r$pkgrel python3"
	install_if="$pkgname=$pkgver-r$pkgrel vim"

	amove usr/share/merlin/vim
}

sha512sums="
cc2cf2c208091b3ae435a8124617e56f2002b7091532002ab49a1f817d90a5c4f9cf0bc5741dc7f2526e0352c3ca95b42c3b3a17c6cbfb80ad73d42310a25d22  merlin-4.5.tar.bz2
"
